package nc.bs.pub.action;

import com.ctc.wstx.util.ExceptionUtil;

import nc.bs.framework.common.NCLocator;
import nc.bs.pubapp.pf.action.AbstractPfAction;
import nc.bs.pubapp.pub.rule.ApproveStatusCheckRule;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.bs.yst.pb.plugin.bpplugin.PBPluginPoint;
import nc.vo.yst.pb.AggPbHVO;
import nc.itf.yst.IPBMaintain;

public class N_H0H3_APPROVE extends AbstractPfAction<AggPbHVO> {

	public N_H0H3_APPROVE() {
		super();
	}

	@Override
	protected CompareAroundProcesser<AggPbHVO> getCompareAroundProcesserWithRules(
			Object userObj) {
		CompareAroundProcesser<AggPbHVO> processor = new CompareAroundProcesser<AggPbHVO>(
				PBPluginPoint.APPROVE);
		processor.addBeforeRule(new ApproveStatusCheckRule());
		return processor;
	}

	@Override
	protected AggPbHVO[] processBP(Object userObj,
			AggPbHVO[] clientFullVOs, AggPbHVO[] originBills) {
		AggPbHVO[] bills = null;
		IPBMaintain operator = NCLocator.getInstance().lookup(IPBMaintain.class);
		
		try {
		    for(int i=0;i<originBills.length;i++){
		    	clientFullVOs[i].getParentVO().setAttributeValue("bbzx", "Y");
		    }
			bills = operator.approve(clientFullVOs, originBills);

//			operator.UpdatePbHVO(bills[0].getPrimaryKey(),"N");
			
//			String sjbbzj=clientFullVOs[0].getParentVO().getAttributeValue("def1")==null?"":clientFullVOs[0].getParentVO().getAttributeValue("def1").toString();
//			if("".equals(sjbbzj)){
//				operator.UpdatePbHVO(bills[0].getPrimaryKey(),"Y");
//			}else{
//				operator.UpdatePbHVO(sjbbzj,"N");
//				operator.UpdatePbHVO(bills[0].getPrimaryKey(),"Y");
//			}
			
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException(e.getMessage());
		}
		return bills;
	}

}
